﻿--
--
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'spZeusPackageStore' AND type = 'P')
BEGIN
  DROP PROCEDURE spZeusPackageStore
END
GO

-- HU - Rakomány betárolás
-- EN - Package Storing
--
CREATE PROCEDURE spZeusPackageStore
(@AccessToken INTEGER, @Code NVARCHAR(20), @LocationCode NVARCHAR(20))
 AS
BEGIN
  DECLARE
    @Err INTEGER,
    @Rows INTEGER,
    @UserID INTEGER,
    @Lang NVARCHAR(10)

  EXEC @Err = spAccessTokenCheck @AccessToken, @UserID OUTPUT, @Lang OUTPUT

  IF (@Err != 0)
    GOTO __ERROR__

  -- 
  --
  UPDATE ZeusPackage
     SET LocationCode = @LocationCode
   WHERE Code = @Code

  SELECT @Rows = @@ROWCOUNT
  
  IF (@Rows != 1) BEGIN

    IF (@Lang = 'HU')
      RAISERROR (N'Nincs ilyen rakomány ! %s', 16, 1, @Code)

    IF (@Lang = 'EN')
      RAISERROR (N'Package not found ! %s', 16, 1, @Code)

    IF (@Lang = 'DE')
      RAISERROR (N'Keine solche Fracht ! %s', 16, 1, @Code)

    GOTO __ERROR__
  END

  -- HU - Visszaadja ennek a Rakománynak az adatait
  -- EN - Get the package details
  --
  SELECT Code, ArticleCode, ArticleName, CONVERT(DATE, Expired) Expired, LocationCode, Quantity, UnitCode, N'' Notes
    FROM ZeusPackage
   WHERE Code = @Code
    
-- Well done.
--
  RETURN(0)

-- We have a problem !
--
__ERROR__:
  RETURN(1)
END
GO
